

NDS_version = GetAddOnMetadata("NoDuelSpam", "Version"); -- automatically get the addon version number

-- Set the patterns that we're going to be looking for to suppress - This should be localized later.

--local NDS_Duel_Pattern_1  = 'has defeated';
--local NDS_Duel_Pattern_2  = 'has fled from';
--local NDS_Drunk_Patterns = {	[1] = "is looking sober from the",
--				[2] = "seems a little tipsy from the",
--				[3] = "is getting drunk off of",
--				[4] = "is completely smashed from the",
--				[5] = "seems to be sobering up",
--				[6] = "looks tipsy",
--				[7] = "looks drunk",
--				[8] = "looks completely smashed",
--		};

-- Set up the count variables.
local NDS_Duel_Won_Count = 0;
local NDS_Duel_Ran_Count = 0;
local NDS_Drunk_Count = 0;


-- Set up the Slash Commands and Handler
SLASH_NODUELSPAM1, SLASH_NODUELSPAM2 = '/nds', '/noduelspam'; 
local function handler(msg, editbox)
 local cmd = msg:lower()
 if cmd == 'ver' then
  print('NoDuelSpam v'..NDS_version);
 elseif cmd == 'count' then
  print(NDS_Status_1, NDS_Duel_Won_Count );
  print(NDS_Status_2, NDS_Duel_Ran_Count );   
  print(NDS_Status_3, NDS_Duel_Won_Count + NDS_Duel_Ran_Count );   
  print(NDS_Status_4, NDS_Drunk_Count );   
 elseif cmd == 'print' then
  print('D1 : ', NDS_Duel_Pattern_1);
  print('D2 : ', NDS_Duel_Pattern_2);
  for i,v in ipairs(NDS_Drunk_Patterns) do print(i.." : "..v) end
 else
  print(NDS_Help_1);
  print('/nds ver - ' , NDS_Help_2 );
  print('/nds count - ', NDS_Help_3 );
 end -- if
end -- handler
SlashCmdList["NODUELSPAM"] = handler; 


-- Filters the Duel/Drunk Spam 
function NDS_DuelSpamFilter(self, event, msg)
	
	if (msg:find(NDS_Duel_Pattern_1)) then 
--		print ('NDS Saw a Duel Won Spam!');
		NDS_Duel_Won_Count = NDS_Duel_Won_Count + 1;
		return true
	end -- if
		
	if (msg:find(NDS_Duel_Pattern_2)) then 
--		print ('NDS Saw a Duel Ran Away Spam!');
		NDS_Duel_Ran_Count = NDS_Duel_Ran_Count + 1;
		return true
	end -- if
	

	for i,v in ipairs(NDS_Drunk_Patterns) do
		if (msg:find(v)) then 
--			print ('NDS Saw a Drunk Spam!');
			NDS_Drunk_Count = NDS_Drunk_Count + 1;
			return true
		end -- if

	end -- for

	return false
end -- Function DuelSpamFilter


function NDS_OnLoad() 
  -- Tell the player that the addon is loaded
  print('NoDuelSpam v'..NDS_version..' loaded.'); 

  -- Add the Duel Spam Filter to the Chat Frame's Message Event Filter
  ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", NDS_DuelSpamFilter);
  
end --OnLoad
